//
//  HWComposePhotoView.m
//  01-黑马微博
//
//  Created by lanou3g on 15/9/21.
//  Copyright (c) 2015年 heima. All rights reserved.
//

#import "HWComposePhotoView.h"

@implementation HWComposePhotoView
- (void)addPhoto:(UIImage *)image{
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.image = image;
    [self addSubview:imageView];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    NSInteger count = self.subviews.count;
    NSInteger maxRow = 4;
    CGFloat imageWH = 70;
    CGFloat imageMargin = (self.width - maxRow * imageWH) / (maxRow + 1);
    
    for (int i = 0; i<count; i++) {
        UIImageView *photoView = self.subviews[i];
        int col = i % maxRow;
        int row = i / maxRow;
        photoView.x = col * (imageWH + imageMargin) + imageMargin;
        photoView.y = row * (imageWH + imageMargin) + 100;
        photoView.width = imageWH;
        photoView.height = imageWH;
    }
}
@end
